import {ref, computed} from 'vue'
import {defineStore} from "pinia";

export const useTokenStore = defineStore('token', () => {
    const token = ref(null)
    const tokenStr = computed(() => {
        return token.value
    })

    //更新token
    function update(tk) {
        token.value = tk;
    }

    //重置token
    function $reset() {
        token.value = null;
    }

    return {token, tokenStr, update, $reset}
}, {
    persist: {
        key: "token",
        storage: sessionStorage,
        paths: ['token']
    }
})
